<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet 
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:dt="http://exslt.org/dates-and-times"
    extension-element-prefixes="dt">
<xsl:output 
    method="xml" 
    version="1.0" 
    encoding="utf-8" 
    omit-xml-declaration="no" 
    indent="yes" 
    media-type="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="records">
<records>
    <xsl:variable name="currentdate" select="dt:date()"/>
    <xsl:for-each select="record">
    <record>
        <ispayed/>
        <block/>
        <blocked/>
        <obj_id/>
        <cat>
            <xsl:choose>
                <xsl:when test="rooms = 1">17</xsl:when>
                <xsl:when test="rooms = 2">18</xsl:when>
                <xsl:when test="rooms >= 3">19</xsl:when>
                <xsl:otherwise>16</xsl:otherwise>
            </xsl:choose>
        </cat>
        <type>3</type>
        <uid><xsl:value-of select="unid"/></uid>
        <code><xsl:value-of select="code"/></code>
        <title><xsl:value-of select="title_auto"/></title>
        <description><xsl:value-of select="description"/></description>
        <location>
            <xsl:if test="metro_station_name != ''">
                ст.м. <xsl:value-of select="metro_station_name"/> 
                <xsl:if test="metro_time != ''">
                    <xsl:value-of select="metro_time"/> мин.
                </xsl:if>  
            </xsl:if>
        </location>
        <condition/>
        <other/>
        <rooms><xsl:value-of select="rooms"/></rooms>
        <bedrooms/>
        <wc/>
        <homes/>
        <homes_size/>
        <pp_size/>
        <trade_units/>
        <trade_size/>
        <space><xsl:value-of select="area_living"/></space>
        <level><xsl:value-of select="storey"/></level>
        <position><xsl:value-of select="storeys"/></position>
        <xsl:if test="phone != '' and phone != '-'">
            <lift>1</lift>
        </xsl:if>
        <handicap></handicap>
        <xsl:if test="x_years > 0">
            <yobuilt>19<xsl:value-of select="x_years"/></yobuilt>
        </xsl:if>
        <toheat/>
        <toheat_ufloor/>
        <fireside/>
        <aircondition/>
        <tv/>
        <dsl/>
        <swpool/>
        <xsl:if test="balcony != '' and balcony != '-'">
            <balcony>1</balcony>
        </xsl:if>
        <terrace/>
        <garden/>
        <parkarea/>
        <garage/>
        <rent/>
        <rent_extra/>
        <price>
            <xsl:value-of select="price"/>
        </price>
        <currency>
            <xsl:choose>
                <xsl:when test="price_haggle = 2">EUR</xsl:when>
                <xsl:when test="price_haggle = 3">BYR</xsl:when>
                <xsl:when test="price_haggle = 4">RUR</xsl:when>
                <xsl:otherwise>USD</xsl:otherwise>
            </xsl:choose>
        </currency>
        <exchange_rate>1</exchange_rate>
        <commis/>
        <secure/>
        <receipts/>
        <street><xsl:value-of select="street_name"/></street>
        <streetnr><xsl:value-of select="house_number"/></streetnr>
        <pcode>220000</pcode>
        <town><xsl:value-of select="town_name"/></town>
        <district>
            <xsl:choose>
                <xsl:when test="state_region_id = 1">Брестская</xsl:when>
                <xsl:when test="state_region_id = 2">Витебская</xsl:when>
                <xsl:when test="state_region_id = 3">Гомельская</xsl:when>
                <xsl:when test="state_region_id = 4">Гродненская</xsl:when>
                <xsl:when test="state_region_id = 5">Минская</xsl:when>
                <xsl:when test="state_region_id = 6">Могилевская</xsl:when>
            </xsl:choose>    
        </district>
        <locstate>
            <xsl:choose>
                <xsl:when test="town_district_id = 90">Центральный</xsl:when>
                <xsl:when test="town_district_id = 70">Советский</xsl:when>
                <xsl:when test="town_district_id = 60">Первомайский</xsl:when>
                <xsl:when test="town_district_id = 50">Партизанский</xsl:when>
                <xsl:when test="town_district_id = 10">Заводской</xsl:when>
                <xsl:when test="town_district_id = 20">Ленинский</xsl:when>
                <xsl:when test="town_district_id = 40">Октябрьский</xsl:when>
                <xsl:when test="town_district_id = 30">Московский</xsl:when>
                <xsl:when test="town_district_id = 80">Фрунзенский</xsl:when>
            </xsl:choose>
        </locstate>
        <microstate><xsl:value-of select="town_subdistrict_name"/></microstate>
        <country>BY</country>
        <hits/>
        <hot/>
        <map_x/>
        <map_y/>
        <metadesc><xsl:value-of select="teaser_description"/></metadesc>
        <metakey><xsl:value-of select="teaser_description"/></metakey>
        <created>
            <xsl:value-of select="concat('20', substring(x_date,7,2), '-', substring(x_date,4,2), '-', substring(x_date,1,2))"/>
        </created>
        <created_by>879</created_by>
        <access>0</access>
        <publish_up>
            <xsl:value-of select="substring($currentdate, 1, 10)"/>
        </publish_up>
        <publish_down>
            <xsl:value-of select="substring(dt:add($currentdate, 'P7D'), 1, 10)"/>
        </publish_down>
        <published>1</published>
        <older/>
        <checked_out/>
        <checked_out_time/>
        <newmn>1</newmn>
        <mnfio><xsl:value-of select="x_contact"/></mnfio>
        <mntel><xsl:value-of select="x_phones"/></mntel>
        <is_agent/>
        <timestamp/>
    </record>
    </xsl:for-each>
</records>
</xsl:template>
<xsl:template match="selection">
</xsl:template>
</xsl:stylesheet>